<?php
ini_set('max_execution_time', 600);

$name = $CPL->get_name();
$email = $CPL->get_email();
$category_id = '114';
$metro_id='21';
$phone='89166603943';

$title='hhhh';
$description = $desc;
//$city=
$param='102085555';
$parameters='private=1&seller_name=&manager=&email=lkjlkjl%40jj.ww&phone=65456464656&location_id=637640&metro_id=2&district_id=&category_id=114&params%5B716%5D=10213&title=Kljlk&description=.knk.ml&price=0&image=&service_code=free&main_form_submit=%D0%9F%D1%80%D0%BE%D0%B4%D0%BE%D0%BB%D0%B6%D0%B8%D1%82%D1%8C+%D1%81+%D0%BF%D0%B0%D0%BA%D0%B5%D1%82%D0%BE%D0%BC+%C2%AB%D0%9E%D0%B1%D1%8B%D1%87%D0%BD%D0%B0%D1%8F+%D0%BF%D1%80%D0%BE%D0%B4%D0%B0%D0%B6%D0%B0%C2%BB';
//'&title='.$nazvanie.'&main_form_submit=Далее';
//var_dump($parameters);die;
function curl_get($parameters,$host, $referer = null){
	
    $ch = curl_init();
    //$cookie = str_replace('\\', '/', dirname(__FILE__)) . 'cookie.txt';
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_REFERER, $referer);
    curl_setopt($ch, CURLOPT_USERAGENT, "headers 
User-Agent: BlackBerry8100/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/179");
    curl_setopt($ch, CURLOPT_URL, $host);
    curl_setopt($ch, CURLOPT_COOKIEJAR,$_SERVER['DOCUMENT_ROOT'].'/cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE,$_SERVER['DOCUMENT_ROOT'].'/cookie.txt');
    curl_setopt($ch, CURLOPT_POST, 1);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$parameters);
    curl_setopt ($ch, CURLOPT_VERBOSE, 2); // Отображать детальную информацию о соединении
    curl_setopt ($ch, CURLOPT_ENCODING, 0);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    
    $hdr=array(
  
    'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0',
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    		'Host	m.avito.ru',
    'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
    'Accept-Encoding: gzip, deflate',
    'Cookie: campanja_id=0-1575104474-33078104914-1375320405988; u=1o6prqyb.m3jku5.e9j5d8q2k4; __utma=99926606.44318105.1381616577.1381957899.1381961399.8; __utmz=99926606.1381616577.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _jsbextsk=1; __gads=ID=b190760b695fea05:T=1381616579:S=ALNI_MZUVYrK5okL8XXH1brn0XDRkiArmA; auth=1; anid=13c47b2a60f4d7c2fc38caaa52052870%3B0; avito_ef_seller=1; sessid=c76ee3e901df0aa569aa9deeabcbb363.1381856505; __utmc=99926606; vkadvtm=1; __utmb=99926606.2.10.1381961399',
    'Connection: keep-alive',
    'Content-Type: application/x-www-form-urlencoded',
    	
   );
   curl_setopt($ch, CURLOPT_HTTPHEADER,$hdr);
   //header('Access-Control-Allow-Origin: *');
    //curl_setopt($ch, CURLOPT_COOKIE, "sessid=de3e9274a96c064fa308bedf70710a79.1381710012;u=1o6qdlss.m3jku5.e9kedila7e");
    $html = curl_exec($ch);
      
    echo curl_error($ch);
    curl_close($ch);
    
    return $html;
}
 
$text = urlencode('');

$result = curl_get($parameters,"http://m.avito.ru/add".$text , 'http://m.avito.ru/add');
//$resh = htmlspecialchars($result);
$result=str_replace ('"Далее"', '"Далее" id="sbmtbtn"',$result);


$result=str_replace ('action="/add"', 'action="http://m.avito.ru/add"',$result);

//var_dump (htmlspecialchars($result));
print $result;
echo "<script>

document.getElementById('seller_name').value = '".'Далее'."';

//document.getElementById('sbmtbtn').click();
 document.myform.submit();
</script>";

$parameters ='title=gggh';

/*$parameters='seller_name='.$name.'&'.'email='.$email.'&'.'category_id='.$category_id.'&'.
		'metro_id='.$metro_id.'&'.'phone='.$phone.'&'.'private=1'.'&'.'params[716]='.'10208'.'&location_id=637640'.
'&title='.$nazvanie.'&main_form_submit=Далее';*/
//$result=curl_get("http://www.avito.ru/additem/confirm".$text , 'http://www.avito.ru/additem');
//var_dump($result);


?>